package com.zb.spring5.environment;

import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;

import java.util.HashMap;
import java.util.Map;

public class EnvironmentSample {

    public static void main(String[] args) {
        GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
        ctx.refresh();

        ConfigurableEnvironment env = ctx.getEnvironment();
        MutablePropertySources propertySources = env.getPropertySources();

        Map<String, Object> appMap = new HashMap<>();
        appMap.put("user.home","application_home");
        //添加第一个会把原有的user.home覆盖掉
        propertySources.addFirst(new MapPropertySource("123123sasdads",appMap));
        System.out.println("user.home:" + System.getProperty("user.home"));
        System.out.println("JAVA_HOME:" + System.getProperty("JAVA_HOME"));

        System.out.println("user.home:" + env.getProperty("user.home"));
        System.out.println("JAVA_HOME:" + env.getProperty("JAVA_HOME"));
        System.out.println("application_home:" + env.getProperty("application.home"));
        ctx.close();
    }
}
